<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="description" content="杰克小麻雀的博客" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    彻底弄懂 Python3中入参里的*号的作用 |  半亩方塘
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>
<body>
  <div id="app">
    
      
      <canvas width="1777" height="841"
        style="position: fixed; left: 0px; top: 0px; z-index: 99999; pointer-events: none;"></canvas>
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-彻底弄懂 Python3中入参里的星号的作用"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  彻底弄懂 Python3中入参里的*号的作用
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/07/25/%E5%BD%BB%E5%BA%95%E5%BC%84%E6%87%82%20Python3%E4%B8%AD%E5%85%A5%E5%8F%82%E9%87%8C%E7%9A%84%E6%98%9F%E5%8F%B7%E7%9A%84%E4%BD%9C%E7%94%A8/" class="article-date">
  <time datetime="2020-07-26T04:22:37.000Z" itemprop="datePublished">2020-07-25</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/Python/">Python</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">1.6k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">6 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <blockquote>
<p>作者: 杰克小麻雀<br>原文链接: <a target="_blank" rel="noopener" href="https://blog.csdn.net/yushuaigee/article/details/107567001">https://blog.csdn.net/yushuaigee/article/details/107567001</a></p>
</blockquote>
<p><strong>目录</strong></p>
<ul>
<li><p><a href="#Python3%E4%B8%AD%E5%87%A0%E7%A7%8D%E4%BC%A0%E9%80%92%E5%8F%82%E6%95%B0%E7%9A%84%E6%96%B9%E5%BC%8F%EF%BC%9A">Python3中几种传递参数的方式：</a></p>
</li>
<li><p><a href="#1.%E4%BD%8D%E7%BD%AE%E5%8F%82%E6%95%B0">1.位置参数</a></p>
</li>
<li><p><a href="#2.%E9%BB%98%E8%AE%A4%E5%8F%82%E6%95%B0">2.默认参数</a></p>
</li>
<li><p><a href="#3.%E5%85%B3%E9%94%AE%E5%AD%97%E5%8F%82%E6%95%B0">3.关键字参数</a></p>
</li>
<li><p><a href="#4.%E5%8F%AF%E5%8F%98%E5%8F%82%E6%95%B0">4.可变参数</a></p>
</li>
<li><p><a href="#5.keyword-only%E5%8F%82%E6%95%B0">5.keyword-only参数</a></p>
</li>
<li><p><a href="#6.%E5%8F%82%E8%80%83%E9%93%BE%E6%8E%A5">6.参考链接</a></p>
</li>
</ul>
<p>我们在看代码时，除了能看到普通的定义函数的入参写法，比如 <code>def func(param1, param2):</code> ，可能也会看到入参用 <code>*args, **kwargs</code>  来代替的写法，比如 <code>def func(*args, **kwargs)</code>:，此外还有一种写法，比如 <code>def func(param1, *, param2):</code>，中间多了一个单纯的<strong>星号</strong>，这个用法又是什么意思呢？先从Python中的几种传递参数的方式说起。</p>
<h3 id="Python3-中几种传递参数的方式"><a href="#Python3-中几种传递参数的方式" class="headerlink" title="Python3 中几种传递参数的方式"></a>Python3 中几种传递参数的方式</h3><ol>
<li>位置参数</li>
<li>默认参数</li>
<li>关键字参数</li>
<li>可变参数 (包括可变位置参数，可变关键字参数)</li>
<li>keyword-only参数 (命名关键字参数)</li>
</ol>
<h3 id="位置参数"><a href="#位置参数" class="headerlink" title="位置参数"></a>位置参数</h3><p><strong>位置参数</strong>是最普通、最常见的传参方式，位置参数必须按照先后顺序传入，传入的参数和定义时的参数，一一对应，例如下面的“<code>1</code>”传给了<code>param1</code>，“<code>2</code>”传给了<code>param2</code>：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">param1, param2</span>):</span></span><br><span class="line">    print(<span class="string">&quot;param1:&quot;</span>, param1)</span><br><span class="line">    print(<span class="string">&quot;param2:&quot;</span>, param2)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 输出：</span></span><br><span class="line"><span class="comment"># param1: 1</span></span><br><span class="line"><span class="comment"># param2: 2</span></span><br></pre></td></tr></table></figure>
<h3 id="默认参数"><a href="#默认参数" class="headerlink" title="默认参数"></a>默认参数</h3><p><strong>默认参数</strong>也比较常见，函数定义时给某个参数设置默认值，调用函数时如果不传这个参数，就使用默认值，如果传了就用传入值：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">param1, param2=<span class="number">1</span></span>):</span></span><br><span class="line">    print(<span class="string">&quot;param1:&quot;</span>, param1)</span><br><span class="line">    print(<span class="string">&quot;param2:&quot;</span>, param2)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    print(<span class="string">&quot;未传入默认参数时&quot;</span>)</span><br><span class="line">    func(<span class="number">1</span>)</span><br><span class="line">    print(<span class="string">&quot;传入默认参数时&quot;</span>)</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 输出：</span></span><br><span class="line"><span class="comment"># 未传入默认参数时</span></span><br><span class="line"><span class="comment"># param1: 1</span></span><br><span class="line"><span class="comment"># param2: 1</span></span><br><span class="line"><span class="comment"># 传入默认参数时</span></span><br><span class="line"><span class="comment"># param1: 1</span></span><br><span class="line"><span class="comment"># param2: 2</span></span><br></pre></td></tr></table></figure>
<p>但是这里要注意，定义函数时如果同时有位置参数和默认参数，默认参数一定要在普通参数的后面，否则会报错如。这是Python语法规定，其实也很好理解，如果不规定顺序，像下面这个函数 <code>def func(param1, param2=1, param3):</code> ，如果传入2个参数，<code>func(1, 2)</code>，这个“<code>2</code>”是传给<code>param2</code>的还是<code>param3</code>的会有歧义。</p>
<p><img src="https://cdn.jsdelivr.net/gh/yushuaige/myblog@master/img/20200725192042437.png" alt="20200725192042437.png"></p>
<p>使用默认参数还有一个需要注意的地方，默认参数的默认值尽量使用不可变对象，<code>param2=1</code>、<code>param2=&quot;txt</code>“这种，否则会引起意想不到的问题。关于不可变对象可以参考：<a target="_blank" rel="noopener" href="https://blog.csdn.net/yushuaigee/article/details/96745994#%E4%BA%8C%E3%80%81Python%E4%B8%AD%E7%9A%84%E4%B8%8D%E5%8F%AF%E5%8F%98%E5%AF%B9%E8%B1%A1%E5%92%8C%E5%8F%AF%E5%8F%98%E5%AF%B9%E8%B1%A1">Python中的不可变对象和可变对象</a></p>
<h3 id="关键字参数"><a href="#关键字参数" class="headerlink" title="关键字参数"></a>关键字参数</h3><p><strong>关键字参数</strong>其实不能单独算作一类参数，是Python中比较方便的一个传参方式。就是在调用函数时，指定将哪个实参传给哪个形参，当然指定的形参名字必须是函数定义时所用的名字。其实普通的位置参数、默认参数、可变参数、keyword-only参数都可以用关键字参数的方式传参。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">a, b,  c=<span class="number">3</span>, d=<span class="number">4</span></span>):</span></span><br><span class="line">    print(<span class="string">&quot;a:&quot;</span>, a)</span><br><span class="line">    print(<span class="string">&quot;b:&quot;</span>, b)</span><br><span class="line">    print(<span class="string">&quot;c:&quot;</span>, c)</span><br><span class="line">    print(<span class="string">&quot;d:&quot;</span>, d)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, <span class="number">4</span>)</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>, d=<span class="number">4</span>)</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>, c=<span class="number">3</span>, d=<span class="number">4</span>)</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>, d=<span class="number">4</span>, c=<span class="number">3</span>)</span><br><span class="line">    func(<span class="number">1</span>, b=<span class="number">2</span>, c=<span class="number">3</span>, d=<span class="number">4</span>)</span><br><span class="line">    func(d=<span class="number">4</span>, c=<span class="number">3</span>, b=<span class="number">2</span>, a=<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 输出都是:</span></span><br><span class="line"><span class="comment"># a: 1</span></span><br><span class="line"><span class="comment"># b: 2</span></span><br><span class="line"><span class="comment"># c: 3</span></span><br><span class="line"><span class="comment"># d: 4</span></span><br></pre></td></tr></table></figure>
<h3 id="可变参数"><a href="#可变参数" class="headerlink" title="可变参数"></a><strong>可变</strong>参数</h3><p><strong>可变参数</strong>也叫动态参数，在Python标准库中见到的比较多。使用可变参数传入的参数的个数是动态的，可以是1个、2个到任意个，还可以是0个。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">*args, **kwargs</span>):</span></span><br><span class="line">    print(<span class="string">&quot;type of args: &quot;</span>, <span class="built_in">type</span>(args))</span><br><span class="line">    print(<span class="string">&quot;args:&quot;</span>, args)</span><br><span class="line">    print(<span class="string">&quot;type of kwargs: &quot;</span>, <span class="built_in">type</span>(kwargs))</span><br><span class="line">    print(<span class="string">&quot;kwargs:&quot;</span>, kwargs)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>, a=<span class="number">3</span>, b=<span class="number">4</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 输出</span></span><br><span class="line"><span class="comment"># type of args:  &amp;lt;class &#x27;tuple&#x27;&amp;gt;</span></span><br><span class="line"><span class="comment"># args: (1, 2)</span></span><br><span class="line"><span class="comment"># type of kwargs:  &amp;lt;class &#x27;dict&#x27;&amp;gt;</span></span><br><span class="line"><span class="comment"># kwargs: &#123;&#x27;a&#x27;: 3, &#x27;b&#x27;: 4&#125;</span></span><br></pre></td></tr></table></figure>
<p>可以看到动态参数分两种，一个是<em>开头，例如</em><code>args</code>，另一个是<code>**</code>开头，例如<code>**kwargs</code>。其中<code>args</code>和<code>kwargs</code>完全可以像其他参数一样自己命名，只是约定俗成的用<code>*args</code>和<code>**kwargs</code>，使用这两个IDE也会自动联想补全。<code>args</code>的类型是元组，调用函数时可以传入任意多的参数，这些参数会自动封装到<code>args</code>里，成为一个元组。<code>kwargs</code>的类型是字典，调用函数时可以传入任意多的自定义键值对参数，这些参数会自动封装到<code>kwargs</code>里，成为一个字典。</p>
<p>用<code>*args，**kwargs</code>组合的方式理论上可以传入任意值，许多标准库代码都是这样写的，<code>*args</code>必须写在<code>**kwargs</code>前面。但是我觉得如果真的所有函数入参都这样写，代码看起来会比较难懂，还是尽量不用这种方法。</p>
<p>那么在函数里面<code>args</code>和<code>*args</code>，<code>kwargs</code>、<code>*kwargs</code>、<code>**kwargs</code>有什么区别呢？可以试一下对比看看，下图中可以看出，<code>*</code>号在这里只是一个标识作用，是给解释器看的，相当于把元组和字典的键的内容取出来，不用太纠结这个，就是一种规定。</p>
<p><img src="https://cdn.jsdelivr.net/gh/yushuaige/myblog@master/img/20200725195231373.png" alt="20200725195231373.png"></p>
<p>同样可变参数位置参数和默认参数使用时也要注意顺序：位置参数、默认参数或<code>*args</code>、<code>**kwargs</code>。也就是说下面这两种方式都是可以的：</p>
<p><img src="https://cdn.jsdelivr.net/gh/yushuaige/myblog@master/img/20200725200127553.png" alt="20200725200127553.png"></p>
<h3 id="keyword-only参数"><a href="#keyword-only参数" class="headerlink" title="keyword-only参数"></a>keyword-only参数</h3><p><strong>keyword-only参数</strong>是 Python3 中新加入的特性，比较不多见。</p>
<p>定义时有一个单独的<em>号，其实这也只是一种规定，</em>号看上去像是一个参数，其实它不占参数个数，是给解释器看的。规定<code>*</code>号后面的参数，能且只能用<code>key=value</code>的方式传入，也就是上面第3步那种关键字参数传参形式。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">func</span>(<span class="params">a, b, *, c=<span class="number">3</span>, d=<span class="number">4</span></span>):</span></span><br><span class="line">    print(<span class="string">&quot;a:&quot;</span>, a)</span><br><span class="line">    print(<span class="string">&quot;b:&quot;</span>, b)</span><br><span class="line">    print(<span class="string">&quot;c:&quot;</span>, c)</span><br><span class="line">    print(<span class="string">&quot;d:&quot;</span>, d)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">&#x27;__main__&#x27;</span>:</span><br><span class="line">    func(<span class="number">1</span>, <span class="number">2</span>, c=<span class="number">3</span>, d=<span class="number">4</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 输出:</span></span><br><span class="line"><span class="comment"># a: 1</span></span><br><span class="line"><span class="comment"># b: 2</span></span><br><span class="line"><span class="comment"># c: 3</span></span><br><span class="line"><span class="comment"># d: 4</span></span><br></pre></td></tr></table></figure>
<p>上面这个函数如果没有单独的星号，我们可以<code>func(1, 2, 3, 4)</code>, <code>func(1, 2, c=3, 4)</code>, <code>func(1, 2, c=3, d=4)</code>这样调用，而有了这个星号标识，就只能用 <code>func(1, 2, c=3, d=4)</code> 这种方式调用。</p>
<h3 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h3><p><a target="_blank" rel="noopener" href="https://www.liujiangblog.com/course/python/31">Python参数类型——刘江</a></p>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/07/25/%E5%BD%BB%E5%BA%95%E5%BC%84%E6%87%82%20Python3%E4%B8%AD%E5%85%A5%E5%8F%82%E9%87%8C%E7%9A%84%E6%98%9F%E5%8F%B7%E7%9A%84%E4%BD%9C%E7%94%A8/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/python/" rel="tag">python</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/" rel="tag">编程语言</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/08/14/%E5%BD%BB%E5%BA%95%E5%BC%84%E6%87%82%20Linux%20%E4%B8%8B%E7%9A%84%E6%96%87%E4%BB%B6%E6%8F%8F%E8%BF%B0%E7%AC%A6%EF%BC%88fd%EF%BC%89/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            彻底弄懂 Linux 下的文件描述符（fd）
          
        </div>
      </a>
    
    
      <a href="/2020/06/15/%E5%BD%BB%E5%BA%95%E5%BC%84%E6%87%82Python%E6%A0%87%E5%87%86%E5%BA%93%E6%BA%90%E7%A0%81%EF%BC%88%E4%B8%80%EF%BC%89%E2%80%94%E2%80%94%20os%E6%A8%A1%E5%9D%97/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">彻底弄懂Python标准库源码（一）—— os模块</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "zy6yBRj9KkWO2XxsT94n1DIW-gzGzoHsz",
    app_key: "auroBE2PQXkQ05CLi30SFv92",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
   
  
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2020-2021
        <i class="ri-heart-fill heart_icon"></i> 杰克小麻雀
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/favicon.ico" alt="半亩方塘"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/alipay.jpg">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/img/wechat.jpg">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->


<script src="/js/clickBoom2.js"></script>


<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>
<script type="text/javascript">
if(!/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
  document.write('<script type="text/javascript" src="/js/FunnyTitle.js"><\/script>');
  document.write('<script type="text/javascript" src="/js/snow.js"><\/script>');
}
</script>
</html>